import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import path from "path"
//element plus 按需引入
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
//打包兼容
import legacy from '@vitejs/plugin-legacy'

// https://vitejs.dev/config/
export default defineConfig({
  css: {
    preprocessorOptions: {
      //全局less变量混入
      less: {
        additionalData: `@import "${path.resolve(__dirname, "./src/assets/style/index.less")}";`,
        javascriptEnabled: true,
      },
    }
  },
  resolve:{
    alias:{
     "@":path.resolve(__dirname,"./src")
    }
  },
  plugins: [
    vue(),
    Components({
      resolvers: [ElementPlusResolver()],
    }),
    legacy()
  ],
  server: {
    proxy: {
      // 正则表达式写法
      '/api': {
        target: 'https://dev.xiaocaoku.cn',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api/, '')
      }
    }
  }
})
